import { createRouter, createWebHistory } from "vue-router";

const routes = []
const router = createRouter({
    history: createWebHistory(),
    routes
})

const viewModules = import.meta.glob('/src/views/**/*.vue')
const promiseArr = []
for(let k in viewModules) { 
    const mod = viewModules[k]()
    promiseArr.push(mod)
}
const asyncRoutes = await Promise.all(promiseArr)
asyncRoutes.forEach(mod => {

    const route = {
        path: '/' + mod.default.__name,
        name: mod.default.__name,
        component: mod.default
    }
    if(mod.default.__name === 'IndexView') {
        route.path = '/'
    }

    router.addRoute(route)
})

export default router